﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace com.drsofts.age.pluginsdk.utils
{
    public class Logger
    {
        private static Logger _instance;
        public static Logger Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new Logger();

                return _instance;
            }
        }

        private StreamWriter writer;

        private Logger()
        {
            String loggingFileName = System.Web.HttpContext.Current.Server.MapPath(@"~\logging\AGE.log");
            writer = new StreamWriter(new FileStream(loggingFileName, FileMode.OpenOrCreate, FileAccess.Write));
        }

        public void log(String logMessage)
        {
            DateTime date = DateTime.Now;
            String dateOfNow = date.Day + "/" + date.Month + "/" + date.Year + " " + date.Hour + ":" + date.Minute + ":" + date.Second;
            writer.WriteLine(dateOfNow + " - " + logMessage);
            writer.Flush();
        }

        ~Logger()
        {
            writer.Close();
        }
    }
}
